package com.wclass.controller.app;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.wclass.common.ReturnObject;
import com.wclass.entity.BaseAppUser;
import com.wclass.entity.BaseBankCard;
import com.wclass.interceptor.BaseContextHandler;
import com.wclass.service.IBaseBankCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 我的账户-我的银行卡信息 前端控制器
 * </p>
 *
 * @author SEN
 * @since 2019-02-14
 */
@Api(description = "我的账户-我的银行卡管理")
@RestController
@RequestMapping("/bankCard")
public class BankCardController {
    @Autowired
    private IBaseBankCardService baseBankCardService;

    @ApiOperation("新增银行卡信息")
    @RequestMapping(value = "/addBankCardInfo", method = RequestMethod.POST)
    public ReturnObject<Object> addBankCardInfo(@ApiParam("开户行名称") @RequestParam String bankName,
                                                @ApiParam("开户行类型 1储蓄卡 2信用卡") @RequestParam String bankType,
                                                @ApiParam("开户行卡号") @RequestParam String bankNo) {
        baseBankCardService.insertInfo(bankName, bankType, bankNo, BaseContextHandler.getUserID());

        return new ReturnObject<>(0, "获取成功");
    }

    @ApiOperation("删除银行卡信息")
    @RequestMapping(value = "/delBankCardByCardId", method = RequestMethod.POST)
    public ReturnObject<Object> delBankCardByCardId(@ApiParam("cartId") @RequestParam Long cartId) {
        baseBankCardService.deleteById(cartId);
        return new ReturnObject<>(0, "获取成功");
    }

    @ApiOperation("获取银行卡分页信息")
    @RequestMapping(value = "/getBankCardPage", method = RequestMethod.POST)
    public ReturnObject<List<BaseBankCard>> getBankCardPage(@ApiParam("每页条数") @RequestParam(defaultValue = "10") int limit,
                                                            @ApiParam("页数") @RequestParam(defaultValue = "1") int offset) {
        
        EntityWrapper ew = new EntityWrapper<>();
        Page<BaseBankCard> obj = baseBankCardService.selectPage(new Page<>(offset, limit), ew);

        return new ReturnObject<>(0, "获取成功", obj.getTotal(), obj.getPages(), obj.getRecords());
    }

}

